package com.gx.smart.construction.ui.house.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.gx.smart.construction.R
import com.gx.smart.construction.databinding.ItemRecordItemLayoutV3Binding
import com.gx.smart.construction.databinding.ItemRecordItemLayoutV4Binding
import com.gx.smart.construction.ui.house.model.RoomInfo

/**
 * @author: xiaosy
 * 时间: 2022/2/25
 * @Description: java类作用描述
 * @Version: 1.0
 */
class RecordItemPagingDataAdapter(val context: Context) :
    PagingDataAdapter<RoomInfo, RecordItemPagingDataAdapter.ViewHolder>(object :
        DiffUtil.ItemCallback<RoomInfo>() {

        override fun areItemsTheSame(oldItem: RoomInfo, newItem: RoomInfo): Boolean =
            oldItem.id == newItem.id

        override fun areContentsTheSame(oldItem: RoomInfo, newItem: RoomInfo): Boolean =
            oldItem == newItem

    }) {

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val item = getItem(position)
        holder.binding.item = item
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val binding = DataBindingUtil.inflate<ItemRecordItemLayoutV4Binding>(LayoutInflater.from(context),
            R.layout.item_record_item_layout_v4, parent, false)
        return ViewHolder(binding)
    }

    class ViewHolder(val binding: ItemRecordItemLayoutV4Binding) : RecyclerView.ViewHolder(binding.root)

}